package com.example.mqtt.mica.mqtt.comsumer;

import net.dreamlu.iot.mqtt.spring.client.MqttClientSubscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;

/**
 * @author ghl
 * @date 2023/11/16 11:12
 * @note
 */
@Service
public class MqttConsumer {

    private static final Logger logger = LoggerFactory.getLogger(MqttConsumer.class);


    /**
     * 通过注解topic 订阅消息
     *
     * @param topic
     * @param payload
     */
    @MqttClientSubscribe("/mqttdemo/#")
    public void subQos0(String topic, byte[] payload) {
        logger.warn("接收消息 topic:[{}] ", topic);
        logger.warn("接收消息 payload:[{}] ", new String(payload, StandardCharsets.UTF_8));
    }


}
